Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-5118] Added tests for presence and occupancy #197

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Dec 15, 2024

Closes #114

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for real-time presence management in chat rooms
    • Introduced enhanced room lifecycle and occupancy tracking
  • Tests

    • Expanded test coverage for room presence, messages, and lifecycle management
    • Added comprehensive mock implementations for testing real-time interactions
  • Improvements

    • Enhanced protocol flexibility for room and presence management
    • Improved error handling and state management in chat room interactions

@ably ably deleted a comment from coderabbitai bot Dec 15, 2024
@maratal maratal force-pushed the 114-tests branch 3 times, most recently from a58094a to 7539cf7 Compare December 16, 2024 00:35
@maratal maratal changed the title [ECO-5118] Added tests for occupancy [ECO-5118] Added tests for occupancy, presence and typing Dec 16, 2024
@ably ably deleted a comment from coderabbitai bot Dec 16, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat December 19, 2024 13:31 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat December 23, 2024 00:51 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat December 31, 2024 20:52 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 3, 2025 23:37 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 4, 2025 00:37 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 4, 2025 23:36 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 6, 2025 10:07 Inactive
Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces several enhancements to the AblyChat framework's testing and presence management infrastructure. The changes include adding a new RealtimePresenceProtocol, modifying the RoomFeature type flexibility, and creating comprehensive test suites for room presence, occupancy, and messages. The modifications focus on improving test coverage, mocking capabilities, and protocol abstractions for real-time communication features.

Changes

File Change Summary
Sources/AblyChat/Dependencies.swift Added new RealtimePresenceProtocol conforming to ARTRealtimePresenceProtocol and Sendable
Sources/AblyChat/RoomFeature.swift Updated contributor property to use protocol composition type
Tests/AblyChatTests/* Added multiple test suites for messages, room presence, and occupancy
Tests/AblyChatTests/Helpers/Helpers.swift Added convenience methods and extensions for testing
Tests/AblyChatTests/Mocks/* Enhanced mock implementations for realtime channels, presence, and lifecycle contributors

Assessment against linked issues

Objective Addressed Explanation
Add more tests for presence
Add more tests for occupancy

Possibly related PRs

Suggested reviewers

  • umair-ably
  • lawrence-forooghian

Poem

🐰 In the realm of realtime chat,
Protocols dance, mocks take their stat
Presence flows, tests multiply
Our code grows wings and learns to fly!
Rabbit's code review, a joyful art 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 9, 2025 19:02 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 12, 2025 19:34 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 12, 2025 21:14 Inactive
@maratal maratal changed the title [ECO-5118] Added tests for occupancy, presence and typing [ECO-5118] Added tests for presence and occupancy Jan 12, 2025
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 12, 2025 22:41 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 19, 2025 12:26 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 19, 2025 12:29 Inactive
@maratal maratal force-pushed the 114-tests branch 2 times, most recently from 6fa21e5 to 6c63f61 Compare January 19, 2025 18:02
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 19, 2025 18:04 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/197/AblyChat January 19, 2025 18:30 Inactive
@maratal
Copy link
Collaborator Author

maratal commented Jan 19, 2025

Spec coverage test issue - ably/specification#269

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (1)

36-54: Enhance subscription test coverage.

While the test verifies basic subscription functionality, consider testing multiple events and edge cases:

  • Multiple occupancy updates
  • Zero occupancy
  • Maximum connection/presence counts
Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift (1)

93-96: Consider adding bounds checking for the delay parameter.

While the implementation is correct, it might be good to add an upper bound check to prevent excessive delays in tests.

 case let .completeAndChangeState(completeResult, newState, milliseconds):
+    guard milliseconds <= 5000 else {
+        throw ARTErrorInfo(message: "Delay cannot exceed 5 seconds")
+    }
     if milliseconds > 0 {
         try? await Task.sleep(nanoseconds: milliseconds * 1_000_000)
     }
Tests/AblyChatTests/Mocks/MockRealtimePresence.swift (1)

89-95: Consider using a more robust subscription management system.

The current implementation only supports a single subscriber. Consider using a collection to support multiple subscribers.

-    private var subscribeCallback: ARTPresenceMessageCallback?
+    private var subscribers: [(ARTEventListener, ARTPresenceMessageCallback)] = []

 func subscribe(_ callback: @escaping ARTPresenceMessageCallback) -> ARTEventListener? {
-    subscribeCallback = callback
+    let listener = ARTEventListener()
+    subscribers.append((listener, callback))
     for member in members {
-        subscribeCallback?(member)
+        callback(member)
     }
-    return ARTEventListener()
+    return listener
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb70b2e and 3fdad4d.

📒 Files selected for processing (10)
  • Sources/AblyChat/Dependencies.swift (1 hunks)
  • Sources/AblyChat/RoomFeature.swift (1 hunks)
  • Tests/AblyChatTests/DefaultMessagesTests.swift (6 hunks)
  • Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (1 hunks)
  • Tests/AblyChatTests/DefaultRoomPresenceTests.swift (1 hunks)
  • Tests/AblyChatTests/Helpers/Helpers.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (5 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimePresence.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRoomLifecycleContributor.swift (2 hunks)
  • Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16)
  • GitHub Check: Example app, tvOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16)
  • GitHub Check: Example app, iOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16)
  • GitHub Check: Example app, macOS (Xcode 16)
  • GitHub Check: SPM (Xcode 16)
  • GitHub Check: Xcode, tvOS (Xcode 16)
  • GitHub Check: Xcode, iOS (Xcode 16)
  • GitHub Check: Xcode, macOS (Xcode 16)
🔇 Additional comments (22)
Sources/AblyChat/Dependencies.swift (1)

28-28: LGTM!

The new RealtimePresenceProtocol is well-defined with appropriate protocol inheritance. The Sendable conformance is particularly good for actor isolation.

Tests/AblyChatTests/DefaultRoomOccupancyTests.swift (2)

8-31: LGTM! Well-structured occupancy check test.

The test effectively validates the occupancy information retrieval with good mock setup and clear assertions.


58-74: LGTM! Good discontinuity event test.

The test effectively validates discontinuity event propagation with appropriate error simulation.

Tests/AblyChatTests/Helpers/Helpers.swift (3)

25-32: LGTM! Clean convenience initializer.

The convenience initializer for ARTPresenceMessage is well-designed with appropriate defaults.


34-41: LGTM! Comprehensive presence event types.

The static array provides a complete list of presence event types, which is useful for testing all presence scenarios.


43-82: LGTM! Well-structured test helpers.

The RoomLifecycleHelper provides comprehensive utilities for test setup with:

  • Clear documentation for the network delay constant
  • Well-named parameters with sensible defaults
  • Flexible configuration options for different test scenarios
Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift (1)

48-48: LGTM! Good addition of network delay simulation.

The optional delay parameter with a default value of 0 is a good design choice for backward compatibility.

Sources/AblyChat/RoomFeature.swift (1)

66-66: LGTM! Good use of protocol composition.

The change to use protocol composition with any RoomLifecycleContributor & EmitsDiscontinuities improves flexibility while maintaining type safety.

Tests/AblyChatTests/DefaultMessagesTests.swift (1)

13-13: LGTM! Good improvement in test setup clarity.

The consistent addition of attachResult: .success makes the channel attachment state explicit in test setup, improving test clarity and maintainability.

Also applies to: 31-31, 55-56, 84-84, 119-119, 148-148

Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (4)

8-12: LGTM! Clean implementation of presence-related properties.

The mock presence implementation is well-structured, with a private property for the mock and a public computed property that exposes it through the protocol interface.


34-43: LGTM! Proper initialization of mock presence.

The initializer correctly handles the optional mock presence parameter with a default value of nil, maintaining backward compatibility.


75-75: LGTM! State property now reflects attachment status.

The state property implementation now correctly reflects the channel's attachment status, returning .attached for successful attachments and .failed for failures.


Line range hint 90-187: LGTM! Enhanced enum and event listener implementation.

Good improvements:

  • AttachOrDetachResult now conforms to Equatable, enabling equality comparisons in tests
  • The on method now returns a valid ARTEventListener instead of fatalError
Tests/AblyChatTests/DefaultRoomPresenceTests.swift (9)

1-5: LGTM! Proper test file setup with necessary imports.

The test file is well-organized with appropriate imports for testing and the target module.


8-20: LGTM! Clear channel name validation test.

The test properly validates that the channel name follows the expected format: {roomId}::$chat::$chatMessages.


27-118: LGTM! Comprehensive presence enter tests.

The tests thoroughly cover presence enter scenarios:

  • Basic enter operation
  • Enter while attaching
  • Enter with attachment failure
  • Error handling for invalid room states

148-261: LGTM! Thorough presence update tests.

The tests comprehensively cover presence update scenarios:

  • Basic update operation
  • Update while attaching
  • Update with attachment failure
  • Error handling for invalid room states

267-280: LGTM! Clear presence leave test.

The test properly validates that a user can leave presence and verifies the empty presence set afterward.


286-300: LGTM! User presence check test.

The test effectively verifies both positive and negative cases for user presence checks.


307-416: LGTM! Comprehensive presence set retrieval tests.

The tests thoroughly cover get operations:

  • Basic retrieval
  • Retrieval while attaching
  • Retrieval with attachment failure
  • Error handling for invalid states

423-464: LGTM! Thorough presence events subscription test.

The test effectively validates subscription to all presence events:

  • present
  • enter
  • update
  • leave

470-485: LGTM! Clear discontinuity handling test.

The test properly validates that discontinuity events are propagated through the presence implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add more tests for presence and occupancy
1 participant